package fr.greta.centre.action;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import fr.greta.centre.dao.CandidatureDAOImpl;

public class ModifierPromoCandidat extends HttpServlet {

    private static final long serialVersionUID = 1L;

    protected void doGet(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {

    }


    protected void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {

        RequestDispatcher rd = request.getRequestDispatcher("message.jsp");
        
        int idCandidat = Integer.parseInt(request.getParameter("idCandidat"));
        int idPromoActuelle = Integer.parseInt(request.getParameter("idPromotion"));
        int idNouvellePromo = Integer.parseInt(request.getParameter("NouvellePromo"));
        
        CandidatureDAOImpl cdao = new CandidatureDAOImpl();
        
        try {
            
            int resultatSQL = cdao.updatePromoCandidature(idCandidat, idNouvellePromo, idPromoActuelle);
            
            if (resultatSQL == 1){
                request.setAttribute("message", "Promotion changée avec succès.!!");
            }
            else{
                request.setAttribute("message", "Impossible de changer la promotion!!");
            }
            
            rd.forward(request, response);
            
        } catch (SQLException e) {
            
            e.printStackTrace();
            
            request.setAttribute("message", "Pas de mise à jour dans la Base.!!");
            rd.forward(request, response);
        
        }
            
        

    }

}

